<template>
  <div>
    <lb-layout
      v-loading="$store.getters.loading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="#a19f9fb0;"
    >
      <aps-form
        :config="apsForm.formConfig"
        :model="apsForm.formData"
        :formRef="apsForm.formRef"
        :labelWidth="apsForm.labelWidth"
        ref="form"
      ></aps-form>
      <lb-table
        :column="tableData.column"
        height="660"
        :data="tableData.data"
        background
        layout="total, sizes, prev, pager, next, jumper"
      >
      </lb-table>
    </lb-layout>
    <aps-dialog-sub
      v-if="auditShow"
      :loading="loadingSub"
      showReply
      v-on:submitAudit="handlerSubmit"
      v-on:closeAudit="handlerClose"
    ></aps-dialog-sub>
  </div>
</template>

<script>
// import { getStatisticsList } from "@/api/donation/other";
import apsDialogSub from "@/components/apsDialogSub";
export default {
  dicts: ["server_type"],
  components: {
    apsDialogSub,
  },
  name: "stream",
  data() {
    return {
      auditShow: false,
      loadingSub: false,
      apsForm: {
        formRef: "form",
        labelWidth: "120px",
        formData: {},
        formConfig: {
          formAttr: {
            inline: true,
            size: "small",
          },
          properties: {
            //这里是渲染查询表单的表头和类型的数据
            donationName: {
              typeName: "el-date-picker",
              placeholder: "考核月份",
              type: "month",
            },

            asdasd: {
              typeName: "el-select",
              style: "width:auto;",
              render: (h) => {
                let that = this;
                let arr = [];
                that.dict?.type?.server_type.some((item) => {
                  arr.push(item);
                });
                // 数据严谨处理,处理后端数据异常情况
                let valNum = that.$refs?.form?.getFieldsValue().serveShape;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "考核等级",
                        value: valNum,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.form?.setFieldValue("serveShape", value);
                          that.$forceUpdate();
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: parseInt(value),
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
          },
          formSoltButton: [
            {
              label: "搜索",
              type: "primary",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-search",
              click: this.handlerSearchDetail,
            },
            {
              label: "重置",
              type: "primary",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-refresh-left",
              click: this.handleReset,
            },
          ],
        },
      },
      tableData: {
        column: [
          {
            prop: "donationName",
            label: "考核等级",
          },
          {
            prop: "donationSum",
            label: "用能单位",
            showOverflowTooltip: true,
          },
          {
            prop: "strokeCount",
            label: "考核内容",
            showOverflowTooltip: true,
          },
          {
            prop: "strokeCount",
            width: "100",
            label: "考核得分",
          },
          {
            prop: "strokeCount",
            width: "200",
            label: "考核月份",
          },
          {
            prop: "strokeCount",
            width: "100",
            label: "审核状态",
          },
          {
            label: "操作",
            width: "150",
            fixed: "right",
            render: (h, scope) => {
              let that = this;
              return (
                <div>
                  {
                    <el-button
                      type="text"
                      size="small"
                      icon="el-icon-view"
                      onClick={() => {
                        this.handlerAudit(scope.row);
                      }}
                    >
                      审核
                    </el-button>
                  }
                </div>
              );
            },
          },
        ],
        data: [],
      },
      currentPage: 1,
      pageSize: 10,
      total: 0,
    };
  },
  mounted() {
    // this.initData();
  },
  methods: {
    handlerAudit(row) {
      this.auditShow = true;
    },
    close(status) {
      this.show = false;
      if (status) this.initData();
    },
    async initData(currentPage, pageSize, data) {
      let that = this;
      let query = {
        donationName: "",
      };
      if (currentPage) {
        query.pageNum = currentPage;
      } else {
        query.pageNum = that.currentPage;
      }
      if (pageSize) {
        query.pageSize = pageSize;
      } else {
        query.pageSize = that.pageSize;
      }
      if (data) {
        query.donationName = data?.donationName ?? "";
      }
      this.$store.commit("app/updateApiCount", "add");
      await getStatisticsList(query)
        .then((res) => {
          this.$store.commit("app/updateApiCount");
          that.tableData.data = res.rows;
          that.total = res.total;
        })
        .catch((err) => {
          this.$store.commit("app/updateApiCount");
          // this.$message.error("系统错误,请联系管理员!10102");
        });
    },
    handlerSearchDetail(val) {
      //val===1 删除操作成功后分页边界值处理
      let data = {};
      let currentPage = 1;
      if (val === 1) {
        if (
          this.total === (this.currentPage - 1) * this.pageSize + 1 &&
          this.total !== 0 &&
          this.currentPage > 1
        ) {
          currentPage = this.currentPage - 1;
          this.currentPage = currentPage;
        } else {
          currentPage = this.currentPage;
        }
      } else {
        currentPage = this.currentPage;
      }
      data.donationName = this.$refs?.form?.getFieldsValue().donationName;
      this.initData(currentPage, this.pageSize, data);
    },
    handleOperDelete(status, row) {
      let that = this;
      let query = {},
        text = "";
      if (status === 0) {
        query.id = row.id;
        text = "是否确认删除" + (row?.name ?? "该条数据") + "？";
      } else if (status === 1) {
        query.id = this.multipleSelection.map((el) => {
          return el.id;
        });
        text = "是否确认进行批量删除？";
      }
      this.$store.commit("app/updateApiCount", "add");
      this.$modal
        .confirm(text)
        .then(() => {
          getDeleteVideo(query)
            .then((res) => {
              this.$store.commit("app/updateApiCount");
              if (res.code === 700) {
                that.$message.warning(res.msg);
                return false;
              }
              that.$message.success("已删除!");
              that.initData();
            })
            .catch((err) => {
              this.$store.commit("app/updateApiCount");
              // this.$message.error("系统错误,请联系管理员!10128");
            });
        })
        .catch(() => {
          this.$store.commit("app/updateApiCount");
        });
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.handlerSearchDetail();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.handlerSearchDetail();
    },
    handleReset() {
      //重置
      this.$refs?.form?.resetFields();
      this.handlerSearchDetail();
    },
    // 批量删除
    handleDeleteAll() {
      if (this.multipleSelection.length > 0) {
        this.handleOperDelete(1);
      } else {
        this.$message.warning("请选择删除项");
      }
    },
    // 多选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 新增
    handleAdd() {
      this.$router.push({ path: "src\viewsexportsecaindex.vue" });
    },
  },
};
</script>
